-
Notifications
You must be signed in to change notification settings - Fork 28
fix: Use streamable_http_client to avoid DeprecationWarning #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: Use streamable_http_client to avoid DeprecationWarning #132
Conversation
Update the import in client.py to use the new `streamable_http_client` function name instead of the deprecated `streamablehttp_client`. Added backward-compatible import that: - First tries to import the new `streamable_http_client` function - Falls back to the old `streamablehttp_client` for older MCP SDK versions This fixes the DeprecationWarning introduced in MCP SDK v1.24.0: "Use streamable_http_client instead of streamablehttp_client" Fixes aws#128
bidesh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ps06756 Thanks for the change!
I added a comment regarding the compatibility of the two methods. I think the tests might pass either because you were still getting streamablehttp_client imported (because the mcp included is still old) or we have gaps in our tests.
Tests we will look after, but if you could verify that the change works are expected without regression, then happy to approve and merge. Thanks for the change!
|
|
||
| # Return the streamable HTTP client context manager with AWS IAM authentication | ||
| return streamablehttp_client( | ||
| return streamable_http_client( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding from this change modelcontextprotocol/python-sdk#1177 is that the signature has changed on how the client is passed.
If streamable_http_client is imported instead of streamablehttp_client, I think this will break because the new implementation will use a default http_client which will not have the headers, auth etc here set up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch! I had wrongly assumed that we would be using the version > 1.24.0 always,
In this case, how do you suggest we determine whether we are on a new version or old version ?
One option is we can use the packaging dependency and do something like
from importlib.metadata import version
from packaging.version import Version
# Check version at import time
_MCP_VERSION = Version(version('mcp'))
_NEW_API_AVAILABLE = _MCP_VERSION >= Version('1.24.0')
if _NEW_API_AVAILABLE:
from mcp.client.streamable_http import streamable_http_client as _streamable_http_client_new
else:
from mcp.client.streamable_http import streamablehttp_client as _streamablehttp_client_old
Or we can directly check the method signature at runtime and determine that ?
import inspect
_NEW_API_AVAILABLE = False
_streamable_http_client_new = None
_streamablehttp_client_old = None
try:
from mcp.client.streamable_http import streamable_http_client as _candidate
sig = inspect.signature(_candidate)
# New API has 'http_client' param, old API has 'auth' param
if 'http_client' in sig.parameters and 'auth' not in sig.parameters:
_NEW_API_AVAILABLE = True
_streamable_http_client_new = _candidate
except (ImportError, ValueError):
pass
if not _NEW_API_AVAILABLE:
try:
from mcp.client.streamable_http import streamablehttp_client as _streamablehttp_client_old
except ImportError:
from mcp.client.streamable_http import streamable_http_client as _streamablehttp_client_old
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the only way we get rid of the DeprecationWarning is if we update the version. I talked to @wzxxing on any problems with upgrading. Copying his reply here:
The fastmcp v2.14.1 introduced some incompatible change that changes the signature of the the httpx client factory.
The fix should be just to add kw args to this function.
**kw,
3:28
@ps06756 would you be willing to include this change and upgrade the dependency?
If not, then please comment in the linked issue and we will prioritise the fix and update.
|
We should upgrade the fastmcp version instead: v2.14.1 requires the mcp-proxy-for-aws/mcp_proxy_for_aws/utils.py Lines 56 to 69 in ab72798
because the factory will be called with more than just Instead, it will be called with |
Summary
client.pyto use the newstreamable_http_clientfunction name instead of the deprecatedstreamablehttp_clientDetails
The MCP Python SDK v1.24.0 (released Dec 12, 2025) introduced a new
streamable_http_clientfunction and deprecated the oldstreamablehttp_client(see PR #1177).Users running with MCP SDK >= 1.24.0 see the following warning:
This fix uses a try/except import pattern to:
streamable_http_clientwhen available (MCP >= 1.24.0)streamablehttp_clientfor older versions (MCP < 1.24.0)Test plan
uv run pytest tests/unit/test_client.py -v)Fixes #128